package com.his.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.his.pojo.PayRecord;
import com.his.pojo.Register;
import com.his.service.RegisterService;
import com.his.mapper.RegisterMapper;
import com.his.uitl.IdUtils;
import com.his.vo.NumberVo;
import com.his.vo.RegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.sql.Wrapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Administrator
* @description 针对表【register】的数据库操作Service实现
* @createDate 2024-10-14 10:05:19
*/
@Service
public class RegisterServiceImpl extends ServiceImpl<RegisterMapper, Register>
    implements RegisterService{
    @Override
    public NumberVo initRegisterService() {
        NumberVo numberVo=new NumberVo();

        numberVo.setInitNumber(100);
        numberVo.setCurrNumber(20);
        numberVo.setCaseNumber(IdUtils.getCaseNumber());
        return numberVo;
    }

    @Autowired
    private RegisterMapper registerMapper;
    @Override
    public Map<String, Object> queryRegisterListService(
            Integer pageNum, Integer pageSize
            , RegisterVo registerVo) {
        Map<String, Object> result=new HashMap<>();
        //指定分页查询参数
        Page<Object> page = PageHelper.startPage(pageNum, pageSize);

        //查询数据库
        List<Register> registerList = registerMapper.queryRegisterList(registerVo);
        result.put("total",page.getTotal());
        result.put("registerList",registerList);
        return result;
    }

    @Override
    public Integer queryRegisterCountService(RegisterVo registerVo) {
        return registerMapper.queryRegisterCount(registerVo);
    }

    @Override
    public Map<String, Object> queryVisitedListService(Integer pageNum
            , Integer pageSize
            , RegisterVo registerVo) {

        Map<String, Object> result=new HashMap<>();
        //指定分页查询参数
        Page<Object> page = PageHelper.startPage(pageNum, pageSize);

        List<Register> registers = registerMapper.queryVisitedRegListMapper(registerVo);
        result.put("total",page.getTotal());
        result.put("visitedList",registers);
        return result;

    }

    @Override
    public Map<String, Object> queryDrugRegListService
            (Integer pageNum, Integer pageSize, RegisterVo registerVo) {
        Map<String, Object> result=new HashMap<>();
        //指定分页查询参数
        Page<Object> page = PageHelper.startPage(pageNum, pageSize);

        QueryWrapper<Register> wrapper=new QueryWrapper<>();
        wrapper.eq(!StringUtils.isEmpty(registerVo.getCaseNumber())
                ,"case_number",registerVo.getCaseNumber());
        wrapper.eq(!StringUtils.isEmpty(registerVo.getRealName())
                ,"real_name",registerVo.getRealName());
        wrapper.eq("visit_state",registerVo.getVisitState());
        List<Register> registers = registerMapper.selectList(wrapper);
        result.put("total",page.getTotal());
        result.put("visitedList",registers);
        return result;

    }

    @Override
    public Map<String, Object> queryBackRegisterListService(Integer pageNum
            , Integer pageSize, RegisterVo registerVo) {
        Map<String, Object> result=new HashMap<>();
        //指定分页查询参数
        Page<Object> page = PageHelper.startPage(pageNum, pageSize);

        List<Register> registers = registerMapper.queryBackRegisterList(registerVo);
        result.put("total",page.getTotal());
        result.put("backRegList",registers);
        return result;
    }

    @Override
    public Map<String, Object> queryPayRecordListService(Integer pageNum
            , Integer pageSize, RegisterVo registerVo) {
        Map<String, Object> result=new HashMap<>();
        //指定分页查询参数
        Page<Object> page = PageHelper.startPage(pageNum, pageSize);
        //查询数据库
        List<PayRecord> payRecords = registerMapper.queryPayRecordList(registerVo);

        result.put("total",page.getTotal());
        result.put("payRecords",payRecords);
        return result;
    }


}




